﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class TreeNode226 { 
int _val;

    TreeNode226 left;
    TreeNode226 right;


    TreeNode226(int val=0, TreeNode226 left=null, TreeNode226 right=null)
    {
        this._val = val;
        this.left = left;
        this.right = right;

    }


}

class Sol226
{
    //Reverse
    //invert倒转
    //insert插入
    public TreeNode InvertTree( TreeNode root)//递归法
    {

        if(root == null)
        {
            return root;
        }


        TreeNode newRightChild = InvertTree(root.right); 
        TreeNode newLeftChild = InvertTree(root.left);

       root.right = newLeftChild;
        root.left = newRightChild;
        return root;

    }
}
class Program226
{
    static void Main226(string[] args)
    {

        //新建一个二叉树
        Solution105 solution = new Solution105();
        int[] preorder = { 4,2,1,3,7,6,9};
        int[] inorder = { 1,2,3,4,6,7,9};
        TreeNode root = solution.BuildTree(preorder, inorder);
        solution.levelOrder(root);

        Console.WriteLine();
        Sol226 s = new Sol226();
        TreeNode res= s.InvertTree(root);
        solution.levelOrder(res);



    }
}
